#include "RsGisLibRGISPopuRATWithStats.h"
#include "ExtensionManager.h"
#include "ExtensionSession.h"
#include <QVariant>

RsGisLibRGISPopuRATWithStats::RsGisLibRGISPopuRATWithStats(RsgisPortal* ClientPortal, QWidget *parent)
{
	ui = new Ui::RsGisLibRGISPopuRATWithStats();
	ui->setupUi(this);

	Portal = ClientPortal;

	connect(ui->pushButton_InputFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_InputFilePath_clicked()));
	connect(ui->pushButton_clumpsImage, SIGNAL(clicked()), this, SLOT(on_action_Button_ClumpsFilePath_clicked()));
	connect(ui->pushButton_Excecute, SIGNAL(clicked()), this, SLOT(on_action_Button_Excecute_clicked()));

	ui->lineEdit_InputFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\In");
	ui->lineEdit_clumpsImage->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\In");

	QStringList FlagList;
	FlagList.append("False");
	FlagList.append("True");
	ui->comboBox_calcMin->addItems(FlagList);
	ui->comboBox_calcMax->addItems(FlagList);
	ui->comboBox_calcMean->addItems(FlagList);
	ui->comboBox_calcStdDev->addItems(FlagList);
	ui->comboBox_calcSum->addItems(FlagList);

	ui->lineEdit_band->setText("0");
	ui->lineEdit_maxField->setText("0");
	ui->lineEdit_minField->setText("0");
	ui->lineEdit_meanField->setText("0");
	ui->lineEdit_stdDevField->setText("0");
	ui->lineEdit_ratBand->setText("0");
	ui->lineEdit_sumField->setText("0");
	ui->comboBox_calcMin->setCurrentIndex(0);
	ui->comboBox_calcMax->setCurrentIndex(0);
	ui->comboBox_calcMean->setCurrentIndex(0);
	ui->comboBox_calcStdDev->setCurrentIndex(0);
	ui->comboBox_calcSum->setCurrentIndex(0);

	ui->lineEdit_Priority->setText("16");
}

void RsGisLibRGISPopuRATWithStats::on_action_Button_InputFilePath_clicked()
{
	QString str = QFileDialog::getOpenFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "All file(*.*)");
	ui->lineEdit_InputFilePath->setText(str.toUtf8());
}

void RsGisLibRGISPopuRATWithStats::on_action_Button_ClumpsFilePath_clicked()
{
	QString str = QFileDialog::getOpenFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "All file(*.*)");
	ui->lineEdit_clumpsImage->setText(str.toUtf8());
}

void RsGisLibRGISPopuRATWithStats::on_action_Button_Excecute_clicked()
{
	QList<QVariant> SysParaList;
	SysParaList << QVariant(QString("RsGisLib"));
	SysParaList << QVariant(QString("RasterGIS"));
	SysParaList << QVariant(int(ui->lineEdit_Priority->text().toInt()));

	QList<QVariant> AlgParaList;
	AlgParaList << QVariant(QString("PopuRATWithStats"));
	AlgParaList << QVariant(QString(ui->lineEdit_InputFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_clumpsImage->text()));
	AlgParaList << QVariant(int(ui->lineEdit_band->text().toInt()));
	AlgParaList << QVariant(int(ui->comboBox_calcMin->currentIndex()));
	AlgParaList << QVariant(QString(ui->lineEdit_minField->text()));
	AlgParaList << QVariant(int(ui->comboBox_calcMax->currentIndex()));
	AlgParaList << QVariant(QString(ui->lineEdit_maxField->text()));
	AlgParaList << QVariant(int(ui->comboBox_calcMean->currentIndex()));
	AlgParaList << QVariant(QString(ui->lineEdit_meanField->text()));
	AlgParaList << QVariant(int(ui->comboBox_calcStdDev->currentIndex()));
	AlgParaList << QVariant(QString(ui->lineEdit_stdDevField->text()));
	AlgParaList << QVariant(int(ui->comboBox_calcSum->currentIndex()));
	AlgParaList << QVariant(QString(ui->lineEdit_sumField->text()));
	AlgParaList << QVariant(int(ui->lineEdit_ratBand->text().toInt()));

	QVariantList ArgList;
	ArgList << (QVariant)SysParaList;
	ArgList << (QVariant)AlgParaList;

	Portal->goAhead(ArgList);
}